/**
 * file
 */
package com.tdkj.action.front.member.seller.shop;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.shop.BeanShopFriendlyLink;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.shop.IBeanShopService;
import com.tdkj.util.PublicConfing;

public class ShopFriendlyLinkAction extends BaseAction {
	
	private Long id;
	private Long frendId;
	private Long userId;
	
	private List<BeanShopFriendlyLink> links;
	
	private IBeanShopService shopService;
	
	@Override
	public String execute() {
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		userId = user.getId();
		
		String name = this.getQueryInfo().get("name");
		String hql = " from " + BeanShopFriendlyLink.class.getName() + " as bean where 1=1 ";
		hql = hql + " and bean.shop.user.id='"+user.getId()+"' ";
		if(name!=null && !"".equals(name)){
			hql = hql + " and bean.friend.name like '%"+name+"%' ";
		}
		Query query = this.createQuery(hql);
		this.queryByPage(query, "shopFriendlyLinkAction.action", 10);
		return "success";
	}
	
	public String add() {
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		userId = user.getId();
		
		shopService.addFriendlyLinksByUserId(userId, frendId);
		return execute();
	}
	
	public String delete() {
		shopService.delete(frendId, BeanShopFriendlyLink.class);
		return execute();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the frendId
	 */
	public Long getFrendId() {
		return frendId;
	}

	/**
	 * @param frendId the frendId to set
	 */
	public void setFrendId(Long frendId) {
		this.frendId = frendId;
	}

	/**
	 * @return the userId
	 */
	public Long getUserId() {
		return userId;
	}

	/**
	 * @param userId the userId to set
	 */
	public void setUserId(Long userId) {
		this.userId = userId;
	}

	/**
	 * @return the links
	 */
	public List<BeanShopFriendlyLink> getLinks() {
		return links;
	}

	/**
	 * @param links the links to set
	 */
	public void setLinks(List<BeanShopFriendlyLink> links) {
		this.links = links;
	}

	/**
	 * @param shopService the shopService to set
	 */
	@Resource
	public void setShopService(IBeanShopService shopService) {
		this.shopService = shopService;
	}

	
}
